;定义数据段
DATA SEGMENT
    MUSIC_1_FREG DW 3 DUP (578,659,784,523)
                 DW 578,659,330,392,440,262,578,578,523,392,349
                 DW 330,392,523,523,494,440,523,494,392,392,330
                 DW 392,440,523,578,578,523,392,349,330,392,494
                 DW 523,523,494,440,523,494,3 DUP (392),440,-1;音乐频率表
    MUSIC_1_TIME DW 56 dup (10);音乐节拍表  
DATA ENDS
;栈定义
STACKSE SEGMENT
    DB 200 DUP(?)
STACKSE ENDS
;音乐地址
MUSIC_ADD MACRO FREG,TIME 
    LEA SI,FREG
    LEA BP,DS:TIME
ENDM
;代码段定义
CODE SEGMENT
    ASSUME DS:DATA,SS:STACKSE,CS:CODE
START:
    MOV AX,DATA
    MOV DS,AX 
    MOV AX,STACKSE
    MOV SS,AX 
    MOV SP,200
    MUSIC_ADD MUSIC_1_FREG,MUSIC_1_TIME
    CALL MUSIC_ON
EXIT:
    MOV AH,4CH 
    INT 21H 
;定时器42H初始化及声音输出端口61H设置
SOUND PROC NEAR 
    PUSH AX 
    PUSH BX
    PUSH CX
    PUSH DX
    PUSH DI
    MOV AL,0B6H
    OUT 43H,AL
    MOV DX,12
    MOV AX,348CH 
    DIV DI
    OUT 42H,AL
    MOV AL,AH 
    OUT 42H,AL
    IN AL,61H 
    MOV AH,AL 
    OR AL,3
    OUT 61H,AL
TIMER:
    MOV CX,2500
    CALL TIMERF
DELAY:
    DEC BX
    JNZ TIMER
    MOV AL,AH
    OUT 61H,AL
    POP DI
    POP DX
    POP CX
    POP BX
    POP AX
    RET
SOUND ENDP

TIMERF PROC NEAR
       PUSH AX
TIMERF1:
       IN AL,61H 
       AND AL,10H 
       CMP AL,AH 
       JE TIMERF1
       MOV AH,AL
       LOOP TIMERF1
       POP AX
       RET
TIMERF ENDP
;音乐
MUSIC_ON PROC NEAR
         XOR AX,AX 
FREG:
    MOV DI,[SI]
    CMP DI,0FFFFH
    JE END_MUS 
    MOV BX,DS:[BP]
    CALL SOUND
    ADD SI,2
    ADD BP,2
    JMP FREG
END_MUS:
    RET
MUSIC_ON ENDP
CODE ENDS
     END START



    
